enum LED_ON_OFF {
    //% block="on"
    HIGH,
    //% block="off"
    LOW
}

//% color="#CC00FF" iconWidth=50 iconHeight=40
namespace LED_Light {
    //% block="Turn [LED_ON_OFF] digital pin [LED_PIN] LED" blockType="command"
    //% LED_ON_OFF.shadow="dropdown" LED_ON_OFF.options="LED_ON_OFF" LED_ON_OFF.defl="HIGH"
    //% LED_PIN.shadow="dropdown" LED_PIN.options="PIN_DigitalWrite" 
    
    export function setState(parameter: any, block: any) {
        let led_on_off = parameter.LED_ON_OFF.code;
        let ledPin = parameter.LED_PIN.code;
       
        Generator.addSetup(`ledPinMode_Digital`, `pinMode(${ledPin}, OUTPUT);`);
        Generator.addCode(`digitalWrite(${ledPin}, ${led_on_off});`);
    }


    //% block="Set analog pin [LED_PIN] LED brightness [LED_BRIGHTNESS]" blockType="command"
    //% LED_PIN.shadow="dropdown" LED_PIN.options="PIN_AnalogWrite" 
    //% LED_BRIGHTNESS.shadow="range" LED_BRIGHTNESS.params.min=0 LED_BRIGHTNESS.params.max=1023 LED_BRIGHTNESS.defl=666
    export function setBrightness(parameter: any, block: any) {
        let ledPin = parameter.LED_PIN.code;
        let ledBrightness = parameter.LED_BRIGHTNESS.code;
        Generator.addSetup(`ledPinMode_Analog`, `pinMode(${ledPin}, OUTPUT);`);
        Generator.addCode(`analogWrite(${ledPin}, ${ledBrightness});`);
    }
}
